package com.jk.lesson3;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;

/**
 * Created by Auser on 2016/11/9.
 */
public class PredicateTest {
    public static void main(String...args){
        List<String> strs = Arrays.asList("", "123", "", "3", null, "", "stop");
        Predicate<String> nonEmptyPredicate = s -> !(s == null || s.isEmpty());
        List<String> nonEmpty = filter(strs, nonEmptyPredicate);
        System.out.println(nonEmpty.toString());
    }

    public static <T> List<T> filter(List<T> list, Predicate<T> predicate){
        List<T> res = new ArrayList<>();
        for(T t : list)
            if(predicate.test(t))
                res.add(t);
        return res;
    }
}
